package com.example.spider;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader;
import com.example.spider.provider.why10w.dto.WhyTaskResult;
import org.shoulder.core.util.JsonUtils;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lym
 */
public class Wgwhy10OfflineCategoryReplace {

    public static void main(String[] args) {
        List<File> files = FileUtil.loopFiles("F:\\spider\\wgwhy10");
        Map<String, WhyTaskResult> whyTaskResultMap = new HashMap<>(500);
        for (File file : files) {
            if (!file.getName().endsWith(".json")) {
                FileUtil.move(file, new File("F:/spider/www.10wgwhy.com/html/" + file.getName()), true);
                continue;
            }
            FileReader fileReader = new FileReader(file);
            String json = fileReader.readString();
            WhyTaskResult whyTaskResult = JsonUtils.parseObject(json, WhyTaskResult.class);
            whyTaskResultMap.put(whyTaskResult.getUrl(), whyTaskResult);
        }
        // 保存到文件
        String fileName = "F:/spider/www.10wgwhy.com/result.dict";
        File file = FileUtil.touch(fileName);
        FileUtil.writeString(JsonUtils.toJson(whyTaskResultMap), file, StandardCharsets.UTF_8);
    }


}
